﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class Main_admin : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string id = Session["id"].ToString();
        string conn = "Data Source= . ;Initial Catalog=XSXK; User ID=sa; pwd=123";
        SqlConnection connection = new SqlConnection(conn);
        try
        {
            connection.Open();
            SqlCommand comm = new SqlCommand();
            comm.Connection = connection;

            string str_sql = "select dept from [User]  where userid= '" + id + "' ";
            comm.CommandText = str_sql;

            string dept = Convert.ToString(comm.ExecuteScalar());
            Session["dept"] = dept;          

        }
        catch (SqlException ex)
        {
            Response.Write(ex.Message);
        }

        finally
        {
            connection.Close();//关闭数据库连接
        }
    }
}